#!/usr/bin/perl -w
=head1 NAME

 remove.pl

=head1 SYNOPSIS

 Remove script for dust

=head1 DESCRIPTION

 Portions copied from 'apt-cacher'.

=cut

my $path = $ENV{PATH_INFO};
#############################################################################
### configuration ###########################################################
# Include the library for the config file parser
require '/usr/share/dust/dust-lib.pl';

# Read in the config file and set the necessary variables
my $configfile = '/etc/dust/dust.conf';

my $configref;
eval {
        $configref = read_config($configfile);
};
my %config = %$configref;

# not sure what to do if we can't read the config file...
die "Could not read config file: $@" if $@;

# Now set some things from the config file
# $logfile used to be set in the config file: now we derive it from $logdir
$config{logfile} = "$config{logdir}/access.log";

# $errorfile used to be set in the config file: now we derive it from $logdir
$config{errorfile} = "$config{logdir}/error.log";

################################################

# Now set some things from the config file
$config{reportfile} = "$config{logdir}/report.html";

# Remove the include lines from Apache's httpd.conf
# Thankfully this is a lot easier now we're just symlinking our config file!
if(-d "/etc/apache/conf.d/" ){
	unlink("/etc/apache/conf.d/dust");
}

if(-d "/etc/apache-ssl/conf.d/" ){
	unlink("/etc/apache-ssl/conf.d/dust");
}

if(-d "/etc/apache2/conf.d/" ){
	unlink("/etc/apache2/conf.d/dust.conf");
}

# Delete the store directory and everything in it, in the purge step
#system("rm", "-rf", $config{store_dir});

# Delete the two log files (leaving the directory behind for now)
unlink($config{log_file});
unlink($config{error_file});

exit(0);
